package com.example.demo.sche;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017-6-30.
 */

@Component
public class Task {


    @Autowired
            Task1 task1 ;
    Logger logger = LoggerFactory.getLogger(Task.class);

    @Autowired
    ScheduledTaskRegistrar scheduledTaskRegistrar ;

    public Task(){

        logger.info("task");
    }
    @Scheduled(cron = "0/1 * * * * ?")
    public  void  run(){
//        logger.info(Thread.currentThread()+"run");
        try {
            TimeUnit.SECONDS.sleep(5);

            scheduledTaskRegistrar.addCronTask(new ScheduledMethodRunnable(task1 , "run") , "0/1 * * * * ?");
        }catch (Exception e){

            logger.info(e.getMessage());
        }

    }
}
